<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <!--如果是IE 就以标准渲染-->
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />

    <!-- 视窗——————响应式布局 -->
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />

    <!--当前页面的三要素-->
    <title>运维系统-深中通道一级柜设备</title>
    <meta name="description" content="聚能优电" />
    <meta http-equiv="keywords" content="聚能优电" />
    <script type="text/javascript" src="../js/verify.js"></script>
    <!-- css -->
    <link rel="stylesheet" type="text/css" href="../css/common/common.css" />
    <link rel="stylesheet" type="text/css" href="../css/mainmonitor_szcyj.css" />
</head>

<body>
    <div id="container" class="szcyj">
        <div class="szcyj_01">
            <!--主屏内容-->
            <div class="szcyj_screen">
                <div class="m_title">
                    <a href="JavaScript:history.go(-1);" class="back">
                        <img src="../images/back.svg" alt="">
                    </a>
                    <span class="tit">STS</span>
                </div>
                <div class="m_content">
                    <div class="sb_tit">
                        <span>设备名称:</span>
                        <select id="select" value="" class="arrowdown">
                            <!-- <option value=""></option>
                            <option value="0">北京</option>
                            <option value="1">上海</option>
                            <option value="2">广州</option>
                            <option value="3">深圳</option>
                            <option value="4">杭州</option> -->
                        </select>
                    </div>

                    <div class="stszt cslist">
                        <div class="stszt_tit list_tit">
                            <!-- <span class="tit_icon"></span> -->
                            <span class="tit_con">设备状态</span>
                        </div>
                        <ul class="list_con" id="stszt_con">
                        </ul>
                    </div>

                    <div class="stscs cslist">
                        <div class="stscs_tit list_tit">
                            <!-- <span class="tit_icon"></span> -->
                            <span class="tit_con">设备参数</span>
                        </div>
                        <ul class="list_con" id="stscs_con">
                        </ul>
                    </div>

                    <div class="stscs1 cslist">
                        <div class="stscs1_tit list_tit">
                            <!-- <span class="tit_icon"></span> -->
                            <span class="tit_con">设备参数1</span>
                        </div>
                        <ul class="list_con" id="stscs1_con">
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>


    <script>
        (function (win, doc) {
            var docEl = doc.documentElement || document.body; //获取HTML标签

            var container = doc.getElementById("container"); //container元素
            //判断是移动端设备还是PC,移动 就采用'orientationchange',横竖屏事件，PC端就采用onresize，窗口改变时间
            var resize =
                "onorientationchange" in win ? "orientationchange" : "resize";

            function rem() {
                docEl.style.fontSize = 100 * (container.clientWidth / 750) + "px";
            }

            //监听'DOMContent事件:DOM加载完成执行,如果DOMContent事件，那么执行rem函数
            doc.addEventListener("DOMContentLoaded", rem, false);

            //win下监听resize事件,如果resize事件，那么执行rem函数
            win.addEventListener(resize, rem, false);
        })(window, document);
    </script>
    <!-- js -->
    <script type="text/javascript" src="../js/jquery-3.4.1.js"></script>
    <script type="text/javascript" src="../layer/layer.js"></script>
    <script>
        $(document).ready(function () {
            $.ajax({
                type: "GET",
                dataType: "json",
                url: 'http://112.74.169.99:21021/api/services/app/DeviceService/GetADeviceInfoListByProjectId?id=5&typeid=7',
                beforeSend: function (xhr) {
                    xhr.setRequestHeader("Accept",
                        "application/json, text/javascript, */*; q=0.01");
                    xhr.setRequestHeader("Authorization", accessToken);
                    xhr.setRequestHeader('.AspNetCore.Culture', 'zh-Hans');
                },
                success: function (res) {
                    var onoff = 0;
                    var defaulttimer;
                    var changetimer;
                    // console.log("sts数据 请求成功");
                    var data = res.result;
                    // var data = [];
                    if (data.length === 0) {
                        $(".m_content").html("暂无数据").css({
                            "font-size": "0.5rem",
                            "text-align": "center",
                            "color": "#fff",
                            "margin-top": "2.5rem"
                        });
                    } else {
                        $("#select").html(eachoption(data));
                        if (onoff == 0) {
                            var optionsdefaultid = $("#select option:selected").attr('valueid');
                            updateData(); // 首次加载立即请求数据
                            defaulttimer = setInterval(updateData, 1000); // 首次加载之后，每1s重新请求一次数据
                            function updateData() {
                                $.ajax({
                                    type: "GET",
                                    dataType: "json",
                                    url: 'http://112.74.169.99:21021/api/services/app/ControlDataService/GetNewSTS_HistoryDataByID?Id=' +
                                        optionsdefaultid,
                                    beforeSend: function (xhr) {
                                        xhr.setRequestHeader("Accept",
                                            "application/json, text/javascript, */*; q=0.01"
                                        );
                                        xhr.setRequestHeader("Authorization",
                                            accessToken);
                                        xhr.setRequestHeader('.AspNetCore.Culture',
                                            'zh-Hans');
                                    },
                                    success: function (res) {
                                        // console.log("首次加载设备数据 请求成功");
                                        $("#stszt_con").html('');
                                        $("#stszt_con").html(eachstszt(res));
                                        $("#stscs_con").html('');
                                        $("#stscs_con").html(eachstscs(res));
                                        $("#stscs1_con").html('');
                                        $("#stscs1_con").html(eachstscs1(res));
                                    },
                                    error: function (res) {
                                        console.log("首次加载设备数据 请求失败");
                                    }
                                });
                            }
                        }

                        // 切换下拉框操作
                        $("#select").change(function () {
                            onoff = 1;
                            clearInterval(defaulttimer);
                            clearInterval(changetimer);
                            var optionschangeid = $(
                                "#select option:selected").attr(
                                'valueid');
                            updateChangeData(); // 首次加载立即请求数据
                            changetimer = setInterval(updateChangeData,
                                1000); // 首次加载之后，每1s重新请求一次数据
                            function updateChangeData() {
                                $.ajax({
                                    type: "GET",
                                    dataType: "json",
                                    url: 'http://112.74.169.99:21021/api/services/app/ControlDataService/GetNewSTS_HistoryDataByID?Id=' +
                                        optionschangeid,
                                    beforeSend: function (xhr) {
                                        xhr.setRequestHeader("Accept",
                                            "application/json, text/javascript, */*; q=0.01"
                                        );
                                        xhr.setRequestHeader("Authorization",
                                            accessToken);
                                        xhr.setRequestHeader(
                                            '.AspNetCore.Culture',
                                            'zh-Hans');
                                    },
                                    success: function (res) {
                                        // console.log("切换设备数据 请求成功");
                                        $("#stszt_con").html('');
                                        $("#stszt_con").html(eachstszt(res));
                                        $("#stscs_con").html('');
                                        $("#stscs_con").html(eachstscs(res));
                                        $("#stscs1_con").html('');
                                        $("#stscs1_con").html(eachstscs1(res));
                                    },
                                    error: function (res) {
                                        console.log("切换设备数据 请求失败");
                                    }
                                });
                            }
                        });
                    }
                },
                error: function (res) {
                    console.log("sts数据 请求失败");
                }
            });


            function eachoption(obj) {
                var str = '';
                if (obj.constructor == Array) {
                    for (var i = 0, len = obj.length; i < len; i++) {
                        var option_value = obj[i].devCN;
                        var option_valueid = obj[i].id;
                        str += `<option value="` + option_value + `" valueid="` +
                            option_valueid + `">` +
                            option_value + `
                        </option>`;
                    }
                    return str;
                }
            }

            // 设备状态
            function eachstszt(obj) {
                obj.result.isonline = 0 ? '离线' : '在线'; // 设备在线
                obj.result.parallelOffGridMode = 0 ? '并网' : '离网'; // 并离网模式
                var str = '';
                str += `<li><span class="con_left">设备在线</span><span class="con_right">` + obj.result
                    .isonline +
                    `</span></li>`;
                str += `<li><span class="con_left">并离网模式</span><span class="con_right">` + obj.result
                    .parallelOffGridMode +
                    `</span></li>`;
                return str;
            }

            // 设备参数
            function eachstscs(obj) {
                var str = '';
                str += `<li><span class="con_left">AB线电压(V)</span><span class="con_right">` + obj.result
                    .abLineVoltage +
                    `</span></li>`;
                str += `<li><span class="con_left">BC线电压(V)</span><span class="con_right">` + obj.result
                    .bcLineVoltage +
                    `</span></li>`;
                str += `<li><span class="con_left">CA线电压(V)</span><span class="con_right">` + obj.result
                    .caLineVoltage +
                    `</span></li>`;
                str += `<li><span class="con_left">A相电流(A)</span><span class="con_right">` + obj.result
                    .aElectricCurrent +
                    `</span></li>`;
                str += `<li><span class="con_left">B相电流(A)</span><span class="con_right">` + obj.result
                    .bElectricCurrent +
                    `</span></li>`;
                str += `<li><span class="con_left">C相电流(A)</span><span class="con_right">` + obj.result
                    .cElectricCurrent +
                    `</span></li>`;
                str += `<li><span class="con_left">A相有功(kW)</span><span class="con_right">` + obj.result
                    .aActivePower +
                    `</span></li>`;
                str += `<li><span class="con_left">B相有功(kW)</span><span class="con_right">` + obj.result
                    .bActivePower +
                    `</span></li>`;
                str += `<li><span class="con_left">C相有功(kW)</span><span class="con_right">` + obj.result
                    .cActivePower +
                    `</span></li>`;
                str += `<li><span class="con_left">A相无功(kVar)</span><span class="con_right">` + obj.result
                    .aReactivePower +
                    `</span></li>`;
                str += `<li><span class="con_left">B相无功(kVar)</span><span class="con_right">` + obj.result
                    .bReactivePower +
                    `</span></li>`;
                str += `<li><span class="con_left">C相无功(kVar)</span><span class="con_right">` + obj.result
                    .cReactivePower +
                    `</span></li>`;
                str += `<li><span class="con_left">A相视在(kVA)</span><span class="con_right">` + obj.result
                    .aApparentPower +
                    `</span></li>`;
                str += `<li><span class="con_left">B相视在(kVA)</span><span class="con_right">` + obj.result
                    .bApparentPower +
                    `</span></li>`;
                str += `<li><span class="con_left">C相视在(kVA)</span><span class="con_right">` + obj.result
                    .cApparentPower +
                    `</span></li>`;
                str += `<li><span class="con_left">A相功率因数</span><span class="con_right">` + obj.result
                    .aPowerFactor +
                    `</span></li>`;
                str += `<li><span class="con_left">B相功率因数</span><span class="con_right">` + obj.result
                    .bPowerFactor +
                    `</span></li>`;
                str += `<li><span class="con_left">C相功率因数</span><span class="con_right">` + obj.result
                    .cPowerFactor +
                    `</span></li>`;
                str += `<li><span class="con_left">总有功(kW)</span><span class="con_right">` + obj.result
                    .tReactivePower +
                    `</span></li>`;
                str += `<li><span class="con_left">总无功(kVar)</span><span class="con_right">` + obj.result
                    .tApparentPower +
                    `</span></li>`;
                str += `<li><span class="con_left">总视在(kVA)</span><span class="con_right">` + obj.result
                    .tPowerFactor +
                    `</span></li>`;
                str += `<li><span class="con_left">频率(Hz)</span><span class="con_right">` + obj.result
                    .frequency +
                    `</span></li>`;
                return str;
            }


            // 设备参数1
            function eachstscs1(obj) {
                var str = '';
                str += `<li><span class="con_left">AB线电压1(V)</span><span class="con_right">` + obj.result
                    .abLineVoltage1 +
                    `</span></li>`;
                str += `<li><span class="con_left">BC线电压1(V)</span><span class="con_right">` + obj.result
                    .bcLineVoltage1 +
                    `</span></li>`;
                str += `<li><span class="con_left">CA线电压1(V)</span><span class="con_right">` + obj.result
                    .caLineVoltage1 +
                    `</span></li>`;
                str += `<li><span class="con_left">A相电流1(A)</span><span class="con_right">` + obj.result
                    .aElectricCurrent1 +
                    `</span></li>`;
                str += `<li><span class="con_left">B相电流1(A)</span><span class="con_right">` + obj.result
                    .bElectricCurrent1 +
                    `</span></li>`;
                str += `<li><span class="con_left">C相电流1(A)</span><span class="con_right">` + obj.result
                    .cElectricCurrent1 +
                    `</span></li>`;
                str += `<li><span class="con_left">A相有功1(kW)</span><span class="con_right">` + obj.result
                    .aActivePower1 +
                    `</span></li>`;
                str += `<li><span class="con_left">B相有功1(kW)</span><span class="con_right">` + obj.result
                    .bActivePower1 +
                    `</span></li>`;
                str += `<li><span class="con_left">C相有功1(kW)</span><span class="con_right">` + obj.result
                    .cActivePower1 +
                    `</span></li>`;
                str += `<li><span class="con_left">A相无功1(kVar)</span><span class="con_right">` + obj.result
                    .aReactivePower1 +
                    `</span></li>`;
                str += `<li><span class="con_left">B相无功1(kVar)</span><span class="con_right">` + obj.result
                    .bReactivePower1 +
                    `</span></li>`;
                str += `<li><span class="con_left">C相无功1(kVar)</span><span class="con_right">` + obj.result
                    .cReactivePower1 +
                    `</span></li>`;
                str += `<li><span class="con_left">A相视在1(kVA)</span><span class="con_right">` + obj.result
                    .aApparentPower1 +
                    `</span></li>`;
                str += `<li><span class="con_left">B相视在1(kVA)</span><span class="con_right">` + obj.result
                    .bApparentPower1 +
                    `</span></li>`;
                str += `<li><span class="con_left">C相视在1(kVA)</span><span class="con_right">` + obj.result
                    .cApparentPower1 +
                    `</span></li>`;
                str += `<li><span class="con_left">A相功率因数1</span><span class="con_right">` + obj.result
                    .aPowerFactor1 +
                    `</span></li>`;
                str += `<li><span class="con_left">B相功率因数1</span><span class="con_right">` + obj.result
                    .bPowerFactor1 +
                    `</span></li>`;
                str += `<li><span class="con_left">C相功率因数1</span><span class="con_right">` + obj.result
                    .cPowerFactor1 +
                    `</span></li>`;
                str += `<li><span class="con_left">总有功1(kW)</span><span class="con_right">` + obj.result
                    .tReactivePower1 +
                    `</span></li>`;
                str += `<li><span class="con_left">总无功1(kVar)</span><span class="con_right">` + obj.result
                    .tApparentPower1 +
                    `</span></li>`;
                str += `<li><span class="con_left">总视在1(kVA)</span><span class="con_right">` + obj.result
                    .tPowerFactor1 +
                    `</span></li>`;
                str += `<li><span class="con_left">频率1(Hz)</span><span class="con_right">` + obj.result
                    .frequency1 +
                    `</span></li>`;
                return str;
            }

        });
    </script>

</body>

</html>